package com.isunland.managesystem.ui;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.CustomerDialog;

/**
 * 考勤汇总查询界面:打卡范围dialog
 * 创建者: HuXiaoDan
 * 日期: 2017/1/6 15:58
 */
public class SignTypeDialogFragment extends android.support.v4.app.DialogFragment {
  private int[] choiceIds =
      new int[] { R.string.all, R.string.no_punch, R.string.sign_abnormal, R.string.sign_normal };
  private String[] choiceStrings = new String[choiceIds.length];

  @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) {
    return new AlertDialog.Builder(getActivity()).setSingleChoiceItems(getChoiceName(), 0,
        new DialogInterface.OnClickListener() {
          @Override public void onClick(DialogInterface dialog, int which) {

            String typeCode;
            switch (which) {
              case 0:
                typeCode = "";
                break;
              case 1:
                typeCode = "01";
                break;
              case 2:
                typeCode = "02";
                break;
              case 3:
                typeCode = "03";
                break;

              default:
                typeCode = "";
                break;
            }
            CustomerDialog content = new CustomerDialog(getChoiceName()[which], typeCode);
            if (getTargetFragment() == null) return;
            Intent i = new Intent();
            i.putExtra(AttendanceSummaryQueryFragment.EXTRA_VALUE, content);
            getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, i);
            dialog.dismiss();
          }
        }).create();
  }

  private String[] getChoiceName() {
    for (int i = 0; i < choiceIds.length; i++) {

      choiceStrings[i] = getResources().getString(choiceIds[i]);
    }

    return choiceStrings;
  }
}
